﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SoftWareLab_Project
{
    public partial class _Default : System.Web.UI.Page
    {
        string TotalWork, practicestd;
        private double Stwork = 0, Practice = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["User"]!= null)
                {
                   SetInitialRow(); 
                }
                else
                {
                    Response.Redirect("Login.aspx");
                }
                
            }
        }

        //แสดง Gridview ทั้งหมด
        private void SetInitialRow()
        {
            DataTable dt = new DataTable();
            DataRow dr = null;
            dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
            dt.Columns.Add(new DataColumn("Column1", typeof(string)));
            dt.Columns.Add(new DataColumn("Column2", typeof(string)));

            dr = dt.NewRow();
            dr["RowNumber"] = 1;
            dr["Column1"] = string.Empty;
            dr["Column2"] = string.Empty;

            dt.Rows.Add(dr);
            //dr = dt.NewRow();

            //Store the DataTable in ViewState
            ViewState["CurrentTable"] = dt;
            ViewState["CurrentTable_a"] = dt;
            ViewState["CurrentTable_b"] = dt;
            ViewState["CurrentTable_c"] = dt;
            ViewState["CurrentTable_d"] = dt;
            ViewState["CurrentTable_e"] = dt;
            ViewState["CurrentTable_f"] = dt;
            ViewState["CurrentTable_g"] = dt;
            ViewState["CurrentTable_h"] = dt;
            ViewState["CurrentTable_i"] = dt;
            ViewState["CurrentTable_j"] = dt;
            ViewState["CurrentTable_k"] = dt;

            GV_CourseList.DataSource = dt;
            GV_CourseList.DataBind();
            GV_Adviser.DataSource = dt;
            GV_Adviser.DataBind();
            GV_Cooperative.DataSource = dt;
            GV_Cooperative.DataBind();
            GV_Board.DataSource = dt;
            GV_Board.DataBind();
            GV_Other.DataSource = dt;
            GV_Other.DataBind();
            GV_Print.DataSource = dt;
            GV_Print.DataBind();
            GV_Proficient.DataSource = dt;
            GV_Proficient.DataBind();
            GV_Project.DataSource = dt;
            GV_Project.DataBind();
            GV_culture.DataSource = dt;
            GV_culture.DataBind();
            GV_developer.DataSource = dt;
            GV_developer.DataBind();
            GV_lecture.DataSource = dt;
            GV_lecture.DataBind();
            GV_management.DataSource = dt;
            GV_management.DataBind();
        }

        //---------------------------------------------

        //Gridview วิชาที่สอน  CurrentTable
        private void AddNewRowToGrid_CourseList()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        //extract the TextBox values
                        TextBox tb_lisit1 = (TextBox)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("TB_CourseList");
                        CheckBoxList cb_list = (CheckBoxList)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("CB_Degree");
                        TextBox tb_stdgroup = (TextBox)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("TB_studentGroup");
                        TextBox tb_stdgnum = (TextBox)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("TB_studentNumber");
                        TextBox tb_theorystd = (TextBox)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("TB_TheoryStudent");
                        TextBox tb_practicestd = (TextBox)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("TB_practiceStudent");
                        DropDownList dd_regular = (DropDownList)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("DD_Regular");
                        RadioButtonList rb_Course = (RadioButtonList)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("RB_Course");
                        TextBox tb_theory_tea = (TextBox)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("TB_TheoryTeacher");
                        TextBox tb_practiceTeacher = (TextBox)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("TB_practiceTeacher");



                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;

                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_lisit1.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = cb_list.SelectedValue;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_stdgroup.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_stdgnum.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_theorystd.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_practicestd.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = dd_regular.SelectedValue;
                        dtCurrentTable.Rows[i - 1]["Column1"] = rb_Course.SelectedValue;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_theory_tea.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_practiceTeacher.Text;

                        rowIndex++;
                    }
                    dtCurrentTable.Rows.Add(drCurrentRow);
                    ViewState["CurrentTable"] = dtCurrentTable;

                    GV_CourseList.DataSource = dtCurrentTable;
                    GV_CourseList.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }

            //Set Previous Data on Postbacks
            SetPreviousData_CourseList();
        }
        private void SetPreviousData_CourseList()
        {
            int rowIndex = 0;
            if (ViewState["CurrentTable"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable"];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        TextBox tb_lisit1 =
                            (TextBox)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("TB_CourseList");
                        CheckBoxList cb_list =
                            (CheckBoxList)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("CB_Degree");
                        TextBox tb_stdgroup =
                            (TextBox)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("TB_studentGroup");
                        TextBox tb_stdgnum =
                            (TextBox)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("TB_studentNumber");
                        TextBox tb_theorystd =
                            (TextBox)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("TB_TheoryStudent");
                        TextBox tb_practicestd =
                            (TextBox)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("TB_practiceStudent");
                        DropDownList dd_regular =
                            (DropDownList)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("DD_Regular");
                        RadioButtonList rb_Course =
                            (RadioButtonList)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("RB_Course");
                        TextBox tb_theory_tea =
                            (TextBox)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("TB_TheoryTeacher");
                        TextBox tb_practiceTeacher =
                            (TextBox)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("TB_practiceTeacher");

                        tb_lisit1.Text = dt.Rows[i]["Column1"].ToString();
                        cb_list.SelectedValue = dt.Rows[i]["Column1"].ToString();
                        tb_stdgroup.Text = dt.Rows[i]["Column1"].ToString();
                        tb_stdgnum.Text = dt.Rows[i]["Column1"].ToString();
                        tb_theorystd.Text = dt.Rows[i]["Column1"].ToString();
                        tb_practicestd.Text = dt.Rows[i]["Column1"].ToString();
                        dd_regular.SelectedValue = dt.Rows[i]["Column1"].ToString();
                        rb_Course.SelectedValue = dt.Rows[i]["Column1"].ToString();
                        tb_theory_tea.Text = dt.Rows[i]["Column1"].ToString();
                        tb_practiceTeacher.Text = dt.Rows[i]["Column1"].ToString();

                        rowIndex++;
                    }
                }
            }
        }
        protected void ImBT_CourseList_Click(object sender, ImageClickEventArgs e)
        {
            if (Session["User"]!= null)
            {
               AddNewRowToGrid_CourseList(); 
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
        }
        protected void GV_CourseList_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            SetRowData_CourseList();
            if (ViewState["CurrentTable"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable"];
                DataRow drCurrentRow = null;
                int rowIndex = Convert.ToInt32(e.RowIndex);
                if (dt.Rows.Count > 1)
                {
                    dt.Rows.Remove(dt.Rows[rowIndex]);
                    drCurrentRow = dt.NewRow();
                    ViewState["CurrentTable"] = dt;
                    GV_CourseList.DataSource = dt;
                    GV_CourseList.DataBind();

                    for (int i = 0; i < GV_CourseList.Rows.Count - 1; i++)
                    {
                        GV_CourseList.Rows[i].Cells[0].Text = Convert.ToString(i + 1);
                    }
                    SetPreviousData_CourseList();
                }
            }
        }
        private void SetRowData_CourseList()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        TextBox tb_lisit1 =
                             (TextBox)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("TB_CourseList");
                        CheckBoxList cb_list =
                            (CheckBoxList)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("CB_Degree");
                        TextBox tb_stdgroup =
                            (TextBox)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("TB_studentGroup");
                        TextBox tb_stdgnum =
                            (TextBox)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("TB_studentNumber");
                        TextBox tb_theorystd =
                            (TextBox)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("TB_TheoryStudent");
                        TextBox tb_practicestd =
                            (TextBox)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("TB_practiceStudent");
                        DropDownList dd_regular =
                            (DropDownList)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("DD_Regular");
                        RadioButtonList rb_Course =
                            (RadioButtonList)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("RB_Course");
                        TextBox tb_theory_tea =
                            (TextBox)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("TB_TheoryTeacher");
                        TextBox tb_practiceTeacher =
                            (TextBox)GV_CourseList.Rows[rowIndex].Cells[1].FindControl("TB_practiceTeacher");

                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_lisit1.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = cb_list.SelectedValue;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_stdgroup.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_stdgnum.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_theorystd.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_practicestd.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = dd_regular.SelectedValue;
                        dtCurrentTable.Rows[i - 1]["Column1"] = rb_Course.SelectedValue;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_theory_tea.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_practiceTeacher.Text;
                        rowIndex++;
                    }

                    ViewState["CurrentTable"] = dtCurrentTable;
                    //grvStudentDetails.DataSource = dtCurrentTable;
                    //grvStudentDetails.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }
            //SetPreviousData();
        }
        //---------------------------------------------

        //Gridview ที่ปรึกษาโครงงาน/วิทยานิพนธ์  CurrentTable_a
        private void AddNewRowToGrid_Adviser()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_a"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_a"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        //extract the TextBox values
                        TextBox tb_Subject_Adviser = (TextBox)GV_Adviser.Rows[rowIndex].Cells[1].FindControl("TB_Subject_Adviser");
                        RadioButtonList rb_Adviser = (RadioButtonList)GV_Adviser.Rows[rowIndex].Cells[1].FindControl("rb_Adviser");
                        TextBox tb_GroupNum_Adviser = (TextBox)GV_Adviser.Rows[rowIndex].Cells[1].FindControl("TB_GroupNum_Adviser");
                        TextBox tb_stdnum_Adviser = (TextBox)GV_Adviser.Rows[rowIndex].Cells[1].FindControl("TB_stdnum_Adviser");
                        CheckBoxList cb_Degree_adviser = (CheckBoxList)GV_Adviser.Rows[rowIndex].Cells[1].FindControl("CB_Degree_adviser");


                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;

                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_Subject_Adviser.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = rb_Adviser.SelectedValue;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_GroupNum_Adviser.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_stdnum_Adviser.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = cb_Degree_adviser.SelectedValue;


                        rowIndex++;
                    }
                    dtCurrentTable.Rows.Add(drCurrentRow);
                    ViewState["CurrentTable_a"] = dtCurrentTable;

                    GV_Adviser.DataSource = dtCurrentTable;
                    GV_Adviser.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }

            //Set Previous Data on Postbacks
            SetPreviousData_Adviser();
        }
        private void SetPreviousData_Adviser()
        {
            int rowIndex = 0;
            if (ViewState["CurrentTable_a"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_a"];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        TextBox tb_Subject_Adviser = (TextBox)GV_Adviser.Rows[rowIndex].Cells[1].FindControl("TB_Subject_Adviser");
                        RadioButtonList rb_Adviser = (RadioButtonList)GV_Adviser.Rows[rowIndex].Cells[1].FindControl("rb_Adviser");
                        TextBox tb_GroupNum_Adviser = (TextBox)GV_Adviser.Rows[rowIndex].Cells[1].FindControl("TB_GroupNum_Adviser");
                        TextBox tb_stdnum_Adviser = (TextBox)GV_Adviser.Rows[rowIndex].Cells[1].FindControl("TB_stdnum_Adviser");
                        CheckBoxList cb_Degree_adviser = (CheckBoxList)GV_Adviser.Rows[rowIndex].Cells[1].FindControl("CB_Degree_adviser");

                        tb_Subject_Adviser.Text = dt.Rows[i]["Column1"].ToString();
                        rb_Adviser.SelectedValue = dt.Rows[i]["Column1"].ToString();
                        tb_GroupNum_Adviser.Text = dt.Rows[i]["Column1"].ToString();
                        tb_stdnum_Adviser.Text = dt.Rows[i]["Column1"].ToString();
                        cb_Degree_adviser.SelectedValue = dt.Rows[i]["Column1"].ToString();

                        rowIndex++;
                    }
                }
            }
        }
        private void SetRowData_Adviser()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_a"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_a"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        TextBox tb_Subject_Adviser = (TextBox)GV_Adviser.Rows[rowIndex].Cells[1].FindControl("TB_Subject_Adviser");
                        RadioButtonList rb_Adviser = (RadioButtonList)GV_Adviser.Rows[rowIndex].Cells[1].FindControl("rb_Adviser");
                        TextBox tb_GroupNum_Adviser = (TextBox)GV_Adviser.Rows[rowIndex].Cells[1].FindControl("TB_GroupNum_Adviser");
                        TextBox tb_stdnum_Adviser = (TextBox)GV_Adviser.Rows[rowIndex].Cells[1].FindControl("TB_stdnum_Adviser");
                        CheckBoxList cb_Degree_adviser = (CheckBoxList)GV_Adviser.Rows[rowIndex].Cells[1].FindControl("CB_Degree_adviser");

                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_Subject_Adviser.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = rb_Adviser.SelectedValue;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_GroupNum_Adviser.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_stdnum_Adviser.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = cb_Degree_adviser.SelectedValue;
                        rowIndex++;
                    }

                    ViewState["CurrentTable_a"] = dtCurrentTable;
                    //grvStudentDetails.DataSource = dtCurrentTable;
                    //grvStudentDetails.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }
            //SetPreviousData();
        }
        protected void ImBT_AddAdviser_Click(object sender, ImageClickEventArgs e)
        {
            if (Session["User"]!= null)
            {
              AddNewRowToGrid_Adviser();  
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
        }
        protected void GV_Adviser_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            SetRowData_Adviser();
            if (ViewState["CurrentTable_a"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_a"];
                DataRow drCurrentRow = null;
                int rowIndex = Convert.ToInt32(e.RowIndex);
                if (dt.Rows.Count > 1)
                {
                    dt.Rows.Remove(dt.Rows[rowIndex]);
                    drCurrentRow = dt.NewRow();
                    ViewState["CurrentTable_a"] = dt;
                    GV_Adviser.DataSource = dt;
                    GV_Adviser.DataBind();

                    for (int i = 0; i < GV_Adviser.Rows.Count - 1; i++)
                    {
                        GV_Adviser.Rows[i].Cells[0].Text = Convert.ToString(i + 1);
                    }
                    SetPreviousData_Adviser();
                }
            }
        }
        //--------------------------------------------

        //Gridview สหกิจศึกษา  CurrentTable_b
        private void AddNewRowToGrid_Cooperative()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_b"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_b"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        //extract the TextBox values
                        TextBox tb_CooperativeName = (TextBox)GV_Cooperative.Rows[rowIndex].Cells[1].FindControl("TB_CooperativeName");
                        TextBox tb_Cooperative_num = (TextBox)GV_Cooperative.Rows[rowIndex].Cells[1].FindControl("TB_Cooperative_num");


                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;

                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_CooperativeName.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_Cooperative_num.Text;

                        rowIndex++;
                    }
                    dtCurrentTable.Rows.Add(drCurrentRow);
                    ViewState["CurrentTable_b"] = dtCurrentTable;

                    GV_Cooperative.DataSource = dtCurrentTable;
                    GV_Cooperative.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }

            //Set Previous Data on Postbacks
            SetPreviousData_Cooperative();
        }
        private void SetPreviousData_Cooperative()
        {
            int rowIndex = 0;
            if (ViewState["CurrentTable_b"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_b"];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        TextBox tb_CooperativeName = (TextBox)GV_Cooperative.Rows[rowIndex].Cells[1].FindControl("TB_CooperativeName");
                        TextBox tb_Cooperative_num = (TextBox)GV_Cooperative.Rows[rowIndex].Cells[1].FindControl("TB_Cooperative_num");

                        tb_CooperativeName.Text = dt.Rows[i]["Column1"].ToString();
                        tb_Cooperative_num.Text = dt.Rows[i]["Column1"].ToString();

                        rowIndex++;
                    }
                }
            }
        }
        private void SetRowData_Cooperative()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_b"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_b"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        TextBox tb_CooperativeName = (TextBox)GV_Cooperative.Rows[rowIndex].Cells[1].FindControl("TB_CooperativeName");
                        TextBox tb_Cooperative_num = (TextBox)GV_Cooperative.Rows[rowIndex].Cells[1].FindControl("TB_Cooperative_num");

                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_CooperativeName.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_Cooperative_num.Text;

                        rowIndex++;
                    }

                    ViewState["CurrentTable_b"] = dtCurrentTable;
                    //grvStudentDetails.DataSource = dtCurrentTable;
                    //grvStudentDetails.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }
            //SetPreviousData();
        }
        protected void GV_Cooperative_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            SetRowData_Cooperative();
            if (ViewState["CurrentTable_b"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_b"];
                DataRow drCurrentRow = null;
                int rowIndex = Convert.ToInt32(e.RowIndex);
                if (dt.Rows.Count > 1)
                {
                    dt.Rows.Remove(dt.Rows[rowIndex]);
                    drCurrentRow = dt.NewRow();
                    ViewState["CurrentTable_b"] = dt;
                    GV_Cooperative.DataSource = dt;
                    GV_Cooperative.DataBind();

                    for (int i = 0; i < GV_Cooperative.Rows.Count - 1; i++)
                    {
                        GV_Cooperative.Rows[i].Cells[0].Text = Convert.ToString(i + 1);
                    }
                    SetPreviousData_Cooperative();
                }
            }
        }
        protected void ImBT_AddCooperative_Click(object sender, ImageClickEventArgs e)
        {
            if (Session["User"]!= null)
            {
               AddNewRowToGrid_Cooperative(); 
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
            
        }
        //-------------------------------------------

        //Gridview โครงการวิจัย CurrentTable_c
        private void AddNewRowToGrid_Project()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_c"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_c"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        //extract the TextBox values
                        TextBox tb_Projectname = (TextBox)GV_Project.Rows[rowIndex].Cells[1].FindControl("TB_Projectname");
                        RadioButtonList rb_Projectpeople = (RadioButtonList)GV_Project.Rows[rowIndex].Cells[1].FindControl("RB_Projectpeople");
                        RadioButtonList rb_persenpj = (RadioButtonList)GV_Project.Rows[rowIndex].Cells[1].FindControl("rb_persenpj");
                        TextBox tb_fundProject = (TextBox)GV_Project.Rows[rowIndex].Cells[1].FindControl("TB_fundProject");
                        TextBox tb_startpj = (TextBox)GV_Project.Rows[rowIndex].Cells[1].FindControl("TB_startpj");
                        TextBox tb_endpj = (TextBox)GV_Project.Rows[rowIndex].Cells[1].FindControl("TB_endpj");



                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;

                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_Projectname.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = rb_Projectpeople.SelectedValue;
                        dtCurrentTable.Rows[i - 1]["Column1"] = rb_persenpj.SelectedValue;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_fundProject.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_startpj.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_endpj.Text;

                        rowIndex++;
                    }
                    dtCurrentTable.Rows.Add(drCurrentRow);
                    ViewState["CurrentTable_c"] = dtCurrentTable;

                    GV_Project.DataSource = dtCurrentTable;
                    GV_Project.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }

            //Set Previous Data on Postbacks
            SetPreviousData_Project();
        }
        private void SetPreviousData_Project()
        {
            int rowIndex = 0;
            if (ViewState["CurrentTable_c"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_c"];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        TextBox tb_Projectname = (TextBox)GV_Project.Rows[rowIndex].Cells[1].FindControl("TB_Projectname");
                        RadioButtonList rb_Projectpeople = (RadioButtonList)GV_Project.Rows[rowIndex].Cells[1].FindControl("RB_Projectpeople");
                        RadioButtonList rb_persenpj = (RadioButtonList)GV_Project.Rows[rowIndex].Cells[1].FindControl("rb_persenpj");
                        TextBox tb_fundProject = (TextBox)GV_Project.Rows[rowIndex].Cells[1].FindControl("TB_fundProject");
                        TextBox tb_startpj = (TextBox)GV_Project.Rows[rowIndex].Cells[1].FindControl("TB_startpj");
                        TextBox tb_endpj = (TextBox)GV_Project.Rows[rowIndex].Cells[1].FindControl("TB_endpj");

                        tb_Projectname.Text = dt.Rows[i]["Column1"].ToString();
                        rb_Projectpeople.SelectedValue = dt.Rows[i]["Column1"].ToString();
                        rb_persenpj.SelectedValue = dt.Rows[i]["Column1"].ToString();
                        tb_fundProject.Text = dt.Rows[i]["Column1"].ToString();
                        tb_startpj.Text = dt.Rows[i]["Column1"].ToString();
                        tb_endpj.Text = dt.Rows[i]["Column1"].ToString();

                        rowIndex++;
                    }
                }
            }
        }
        private void SetRowData_Project()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_c"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_c"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        TextBox tb_Projectname = (TextBox)GV_Project.Rows[rowIndex].Cells[1].FindControl("TB_Projectname");
                        RadioButtonList rb_Projectpeople = (RadioButtonList)GV_Project.Rows[rowIndex].Cells[1].FindControl("RB_Projectpeople");
                        RadioButtonList rb_persenpj = (RadioButtonList)GV_Project.Rows[rowIndex].Cells[1].FindControl("rb_persenpj");
                        TextBox tb_fundProject = (TextBox)GV_Project.Rows[rowIndex].Cells[1].FindControl("TB_fundProject");
                        TextBox tb_startpj = (TextBox)GV_Project.Rows[rowIndex].Cells[1].FindControl("TB_startpj");
                        TextBox tb_endpj = (TextBox)GV_Project.Rows[rowIndex].Cells[1].FindControl("TB_endpj");

                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_Projectname.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = rb_Projectpeople.SelectedValue;
                        dtCurrentTable.Rows[i - 1]["Column1"] = rb_persenpj.SelectedValue;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_fundProject.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_startpj.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_endpj.Text;

                        rowIndex++;
                    }

                    ViewState["CurrentTable_c"] = dtCurrentTable;
                    //grvStudentDetails.DataSource = dtCurrentTable;
                    //grvStudentDetails.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }
            //SetPreviousData();
        }
        protected void Imbt_pjAdd_Click(object sender, ImageClickEventArgs e)
        {
            if (Session["User"]!= null)
            {
               AddNewRowToGrid_Project(); 
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
        }
        protected void GV_Project_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            SetRowData_Project();
            if (ViewState["CurrentTable_c"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_c"];
                DataRow drCurrentRow = null;
                int rowIndex = Convert.ToInt32(e.RowIndex);
                if (dt.Rows.Count > 1)
                {
                    dt.Rows.Remove(dt.Rows[rowIndex]);
                    drCurrentRow = dt.NewRow();
                    ViewState["CurrentTable_c"] = dt;
                    GV_Project.DataSource = dt;
                    GV_Project.DataBind();

                    for (int i = 0; i < GV_Project.Rows.Count - 1; i++)
                    {
                        GV_Project.Rows[i].Cells[0].Text = Convert.ToString(i + 1);
                    }
                    SetPreviousData_Project();
                }
            }
        }
        //---------------------------------------------------

        //Gridview การตีพิมพ์ผลงาน CurrentTable_d
        private void AddNewRowToGrid_Print()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_d"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_d"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        //extract the TextBox values
                        TextBox tb_Printname = (TextBox)GV_Print.Rows[rowIndex].Cells[1].FindControl("TB_Printname");
                        RadioButtonList rb_PrintAt = (RadioButtonList)GV_Print.Rows[rowIndex].Cells[1].FindControl("rb_PrintAt");
                        //TextBox tb_MagazinePrint = (TextBox)GV_Print.Rows[rowIndex].Cells[1].FindControl("TB_MagazinePrint");
                        TextBox tb_PrintDate = (TextBox)GV_Print.Rows[rowIndex].Cells[1].FindControl("TB_PrintDate");


                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;

                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_Printname.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = rb_PrintAt.SelectedValue;
            //            dtCurrentTable.Rows[i - 1]["Column1"] = tb_MagazinePrint.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_PrintDate.Text;

                        rowIndex++;
                    }
                    dtCurrentTable.Rows.Add(drCurrentRow);
                    ViewState["CurrentTable_d"] = dtCurrentTable;

                    GV_Print.DataSource = dtCurrentTable;
                    GV_Print.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }

            //Set Previous Data on Postbacks
            SetPreviousData_Print();
        }
        private void SetPreviousData_Print()
        {
            int rowIndex = 0;
            if (ViewState["CurrentTable_d"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_d"];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        TextBox tb_Printname = (TextBox)GV_Print.Rows[rowIndex].Cells[1].FindControl("TB_Printname");
                        RadioButtonList rb_PrintAt = (RadioButtonList)GV_Print.Rows[rowIndex].Cells[1].FindControl("rb_PrintAt");
              //          TextBox tb_MagazinePrint = (TextBox)GV_Print.Rows[rowIndex].Cells[1].FindControl("TB_MagazinePrint");
                        TextBox tb_PrintDate = (TextBox)GV_Print.Rows[rowIndex].Cells[1].FindControl("TB_PrintDate");

                        tb_Printname.Text = dt.Rows[i]["Column1"].ToString();
                        rb_PrintAt.SelectedValue = dt.Rows[i]["Column1"].ToString();
                //        tb_MagazinePrint.Text = dt.Rows[i]["Column1"].ToString();
                        tb_PrintDate.Text = dt.Rows[i]["Column1"].ToString();

                        rowIndex++;
                    }
                }
            }
        }
        private void SetRowData_Print()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_d"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_d"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        TextBox tb_Printname = (TextBox)GV_Print.Rows[rowIndex].Cells[1].FindControl("TB_Printname");
                        RadioButtonList rb_PrintAt = (RadioButtonList)GV_Print.Rows[rowIndex].Cells[1].FindControl("rb_PrintAt");
                  //      TextBox tb_MagazinePrint = (TextBox)GV_Print.Rows[rowIndex].Cells[1].FindControl("TB_MagazinePrint");
                        TextBox tb_PrintDate = (TextBox)GV_Print.Rows[rowIndex].Cells[1].FindControl("TB_PrintDate");

                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;

                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_Printname.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = rb_PrintAt.SelectedValue;
                       // dtCurrentTable.Rows[i - 1]["Column1"] = tb_MagazinePrint.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_PrintDate.Text;

                        rowIndex++;
                    }

                    ViewState["CurrentTable_d"] = dtCurrentTable;
                    //grvStudentDetails.DataSource = dtCurrentTable;
                    //grvStudentDetails.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }
            //SetPreviousData();
        }
        protected void ImbtprintAdd_Click(object sender, ImageClickEventArgs e)
        {
            if (Session["User"]!= null)
            {
               AddNewRowToGrid_Print();  
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
        }
        protected void GV_Print_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            SetRowData_Print();
            if (ViewState["CurrentTable_d"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_d"];
                DataRow drCurrentRow = null;
                int rowIndex = Convert.ToInt32(e.RowIndex);
                if (dt.Rows.Count > 1)
                {
                    dt.Rows.Remove(dt.Rows[rowIndex]);
                    drCurrentRow = dt.NewRow();
                    ViewState["CurrentTable_d"] = dt;
                    GV_Print.DataSource = dt;
                    GV_Print.DataBind();

                    for (int i = 0; i < GV_Print.Rows.Count - 1; i++)
                    {
                        GV_Print.Rows[i].Cells[0].Text = Convert.ToString(i + 1);
                    }
                    SetPreviousData_Print();
                }
            }
        }
        //---------------------------------------------------

        //Gridview เป็นคณะกรรมการ CurrentTable_e
        private void AddNewRowToGrid_Board()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_e"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_e"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        //extract the TextBox values
                        TextBox tb_Boardname = (TextBox)GV_Board.Rows[rowIndex].Cells[1].FindControl("TB_Boardname");
                        TextBox tb_Boardeorder = (TextBox)GV_Board.Rows[rowIndex].Cells[1].FindControl("TB_Boardeorder");


                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;

                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_Boardname.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_Boardeorder.Text;

                        rowIndex++;
                    }
                    dtCurrentTable.Rows.Add(drCurrentRow);
                    ViewState["CurrentTable_e"] = dtCurrentTable;

                    GV_Board.DataSource = dtCurrentTable;
                    GV_Board.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }

            //Set Previous Data on Postbacks
            SetPreviousData_Board();
        }
        private void SetPreviousData_Board()
        {
            int rowIndex = 0;
            if (ViewState["CurrentTable_e"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_e"];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        TextBox tb_Boardname = (TextBox)GV_Board.Rows[rowIndex].Cells[1].FindControl("TB_Boardname");
                        TextBox tb_Boardeorder = (TextBox)GV_Board.Rows[rowIndex].Cells[1].FindControl("TB_Boardeorder");

                        tb_Boardname.Text = dt.Rows[i]["Column1"].ToString();
                        tb_Boardeorder.Text = dt.Rows[i]["Column1"].ToString();

                        rowIndex++;
                    }
                }
            }
        }
        private void SetRowData_Board()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_e"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_e"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        TextBox tb_Boardname = (TextBox)GV_Board.Rows[rowIndex].Cells[1].FindControl("TB_Boardname");
                        TextBox tb_Boardeorder = (TextBox)GV_Board.Rows[rowIndex].Cells[1].FindControl("TB_Boardeorder");

                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;

                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_Boardname.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = tb_Boardeorder.Text;

                        rowIndex++;
                    }

                    ViewState["CurrentTable_e"] = dtCurrentTable;
                    //grvStudentDetails.DataSource = dtCurrentTable;
                    //grvStudentDetails.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }
            //SetPreviousData();
        }
        protected void Imbt_BoardAdd_Click(object sender, ImageClickEventArgs e)
        {
            if (Session["User"]!= null)
            {
                AddNewRowToGrid_Board(); 
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
        }
        protected void GV_Board_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            SetRowData_Board();
            if (ViewState["CurrentTable_e"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_e"];
                DataRow drCurrentRow = null;
                int rowIndex = Convert.ToInt32(e.RowIndex);
                if (dt.Rows.Count > 1)
                {
                    dt.Rows.Remove(dt.Rows[rowIndex]);
                    drCurrentRow = dt.NewRow();
                    ViewState["CurrentTable_e"] = dt;
                    GV_Board.DataSource = dt;
                    GV_Board.DataBind();

                    for (int i = 0; i < GV_Board.Rows.Count - 1; i++)
                    {
                        GV_Board.Rows[i].Cells[0].Text = Convert.ToString(i + 1);
                    }
                    SetPreviousData_Board();
                }
            }
        }
        //-------------------------------------------------

        //Gridview เป็นวิทยากร CurrentTable_f
        private void AddNewRowToGrid_lecture()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_f"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_f"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        //extract the TextBox values
                        TextBox TB_lecturename = (TextBox)GV_lecture.Rows[rowIndex].Cells[1].FindControl("TB_lecturename");
                        RadioButtonList rb_Lecture = (RadioButtonList)GV_lecture.Rows[rowIndex].Cells[1].FindControl("rb_Lecture");
                        TextBox TB_Hour = (TextBox)GV_lecture.Rows[rowIndex].Cells[1].FindControl("TB_Hour");
                        TextBox TB_lecturedate = (TextBox)GV_lecture.Rows[rowIndex].Cells[1].FindControl("TB_lecturedate");
                        TextBox TB_lecturelocation = (TextBox)GV_lecture.Rows[rowIndex].Cells[1].FindControl("TB_lecturelocation");
                        TextBox TB_lecturecredit = (TextBox)GV_lecture.Rows[rowIndex].Cells[1].FindControl("TB_lecturecredit");


                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;

                        dtCurrentTable.Rows[i - 1]["Column1"] = TB_lecturename.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = rb_Lecture.SelectedValue;
                        dtCurrentTable.Rows[i - 1]["Column1"] = TB_Hour.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = TB_lecturedate.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = TB_lecturelocation.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = TB_lecturecredit.Text;

                        rowIndex++;
                    }
                    dtCurrentTable.Rows.Add(drCurrentRow);
                    ViewState["CurrentTable_f"] = dtCurrentTable;

                    GV_lecture.DataSource = dtCurrentTable;
                    GV_lecture.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }

            //Set Previous Data on Postbacks
            SetPreviousData_lecture();
        }
        private void SetPreviousData_lecture()
        {
            int rowIndex = 0;
            if (ViewState["CurrentTable_f"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_f"];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        TextBox TB_lecturename = (TextBox)GV_lecture.Rows[rowIndex].Cells[1].FindControl("TB_lecturename");
                        RadioButtonList rb_Lecture = (RadioButtonList)GV_lecture.Rows[rowIndex].Cells[1].FindControl("rb_Lecture");
                        TextBox TB_Hour = (TextBox)GV_lecture.Rows[rowIndex].Cells[1].FindControl("TB_Hour");
                        TextBox TB_lecturedate = (TextBox)GV_lecture.Rows[rowIndex].Cells[1].FindControl("TB_lecturedate");
                        TextBox TB_lecturelocation = (TextBox)GV_lecture.Rows[rowIndex].Cells[1].FindControl("TB_lecturelocation");
                        TextBox TB_lecturecredit = (TextBox)GV_lecture.Rows[rowIndex].Cells[1].FindControl("TB_lecturecredit");

                        TB_lecturename.Text = dt.Rows[i]["Column1"].ToString();
                        rb_Lecture.SelectedValue = dt.Rows[i]["Column1"].ToString();
                        TB_Hour.Text = dt.Rows[i]["Column1"].ToString();
                        TB_lecturedate.Text = dt.Rows[i]["Column1"].ToString();
                        TB_lecturelocation.Text = dt.Rows[i]["Column1"].ToString();
                        TB_lecturecredit.Text = dt.Rows[i]["Column1"].ToString();

                        rowIndex++;
                    }
                }
            }
        }
        private void SetRowData_lecture()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_f"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_f"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        TextBox TB_lecturename = (TextBox)GV_lecture.Rows[rowIndex].Cells[1].FindControl("TB_lecturename");
                        RadioButtonList rb_Lecture = (RadioButtonList)GV_lecture.Rows[rowIndex].Cells[1].FindControl("rb_Lecture");
                        TextBox TB_Hour = (TextBox)GV_lecture.Rows[rowIndex].Cells[1].FindControl("TB_Hour");
                        TextBox TB_lecturedate = (TextBox)GV_lecture.Rows[rowIndex].Cells[1].FindControl("TB_lecturedate");
                        TextBox TB_lecturelocation = (TextBox)GV_lecture.Rows[rowIndex].Cells[1].FindControl("TB_lecturelocation");
                        TextBox TB_lecturecredit = (TextBox)GV_lecture.Rows[rowIndex].Cells[1].FindControl("TB_lecturecredit");

                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;

                        dtCurrentTable.Rows[i - 1]["Column1"] = TB_lecturename.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = rb_Lecture.SelectedValue;
                        dtCurrentTable.Rows[i - 1]["Column1"] = TB_Hour.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = TB_lecturedate.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = TB_lecturelocation.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = TB_lecturecredit.Text;

                        rowIndex++;
                    }

                    ViewState["CurrentTable_f"] = dtCurrentTable;
                    //grvStudentDetails.DataSource = dtCurrentTable;
                    //grvStudentDetails.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }
            //SetPreviousData();
        }
        protected void Imbt_lectureAdd_Click(object sender, ImageClickEventArgs e)
        {
            if (Session["User"]!= null)
            {
               AddNewRowToGrid_lecture(); 
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
            
        }
        protected void GV_lecture_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            SetRowData_lecture();
            if (ViewState["CurrentTable_f"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_f"];
                DataRow drCurrentRow = null;
                int rowIndex = Convert.ToInt32(e.RowIndex);
                if (dt.Rows.Count > 1)
                {
                    dt.Rows.Remove(dt.Rows[rowIndex]);
                    drCurrentRow = dt.NewRow();
                    ViewState["CurrentTable_f"] = dt;
                    GV_lecture.DataSource = dt;
                    GV_lecture.DataBind();

                    for (int i = 0; i < GV_lecture.Rows.Count - 1; i++)
                    {
                        GV_lecture.Rows[i].Cells[0].Text = Convert.ToString(i + 1);
                    }
                    SetPreviousData_lecture();
                }
            }
        }
        //------------------------------------------------

        //Gridview เป็นผู้ทรงคุณวุฒิ CurrentTable_g
        private void AddNewRowToGrid_Proficient()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_g"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_g"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        //extract the TextBox values
                        TextBox TB_Proficient = (TextBox)GV_Proficient.Rows[rowIndex].Cells[1].FindControl("TB_Proficient");
                        RadioButtonList rb_Proficient = (RadioButtonList)GV_Proficient.Rows[rowIndex].Cells[1].FindControl("rb_Proficient");

                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;
                        dtCurrentTable.Rows[i - 1]["Column1"] = rb_Proficient.SelectedValue;
                        dtCurrentTable.Rows[i - 1]["Column1"] = TB_Proficient.Text;


                        rowIndex++;
                    }
                    dtCurrentTable.Rows.Add(drCurrentRow);
                    ViewState["CurrentTable_g"] = dtCurrentTable;

                    GV_Proficient.DataSource = dtCurrentTable;
                    GV_Proficient.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }

            //Set Previous Data on Postbacks
            SetPreviousData_Proficient();
        }
        private void SetPreviousData_Proficient()
        {
            int rowIndex = 0;
            if (ViewState["CurrentTable_g"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_g"];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        TextBox TB_Proficient = (TextBox)GV_Proficient.Rows[rowIndex].Cells[1].FindControl("TB_Proficient");
                        RadioButtonList rb_Proficient = (RadioButtonList)GV_Proficient.Rows[rowIndex].Cells[1].FindControl("rb_Proficient");
                        rb_Proficient.SelectedValue = dt.Rows[i]["Column1"].ToString();
                        TB_Proficient.Text = dt.Rows[i]["Column1"].ToString();


                        rowIndex++;
                    }
                }
            }
        }
        private void SetRowData_Proficient()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_g"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_g"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        TextBox TB_Proficient = (TextBox)GV_Proficient.Rows[rowIndex].Cells[1].FindControl("TB_Proficient");
                        RadioButtonList rb_Proficient = (RadioButtonList)GV_Proficient.Rows[rowIndex].Cells[1].FindControl("rb_Proficient");

                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;
                        dtCurrentTable.Rows[i - 1]["Column1"] = rb_Proficient.SelectedValue;
                        dtCurrentTable.Rows[i - 1]["Column1"] = TB_Proficient.Text;


                        rowIndex++;
                    }

                    ViewState["CurrentTable_g"] = dtCurrentTable;
                    //grvStudentDetails.DataSource = dtCurrentTable;
                    //grvStudentDetails.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }
            //SetPreviousData();
        }
        protected void Imbt_proficientAdd_Click(object sender, ImageClickEventArgs e)
        {
            if (Session["User"]!= null)
            {
                AddNewRowToGrid_Proficient(); 
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
           
        }
        protected void GV_Proficient_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            SetRowData_Proficient();
            if (ViewState["CurrentTable_g"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_g"];
                DataRow drCurrentRow = null;
                int rowIndex = Convert.ToInt32(e.RowIndex);
                if (dt.Rows.Count > 1)
                {
                    dt.Rows.Remove(dt.Rows[rowIndex]);
                    drCurrentRow = dt.NewRow();
                    ViewState["CurrentTable_g"] = dt;
                    GV_Proficient.DataSource = dt;
                    GV_Proficient.DataBind();

                    for (int i = 0; i < GV_Proficient.Rows.Count - 1; i++)
                    {
                        GV_Proficient.Rows[i].Cells[0].Text = Convert.ToString(i + 1);
                    }
                    SetPreviousData_Proficient();
                }
            }
        }
        //-----------------------------------------------

        //Gridview  อื่นๆ CurrentTable_h
        private void AddNewRowToGrid_Other()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_h"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_h"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        //extract the TextBox values
                        TextBox TB_Other = (TextBox)GV_Other.Rows[rowIndex].Cells[1].FindControl("TB_Other");
                        //RadioButtonList rb_Other = (RadioButtonList)GV_Other.Rows[rowIndex].Cells[1].FindControl("rb_Other");

                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;

                        dtCurrentTable.Rows[i - 1]["Column1"] = TB_Other.Text;
                        // dtCurrentTable.Rows[i - 1]["Column1"] = rb_Other.SelectedValue;

                        rowIndex++;
                    }
                    dtCurrentTable.Rows.Add(drCurrentRow);
                    ViewState["CurrentTable_h"] = dtCurrentTable;

                    GV_Other.DataSource = dtCurrentTable;
                    GV_Other.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }

            //Set Previous Data on Postbacks
            SetPreviousData_Other();
        }
        private void SetPreviousData_Other()
        {
            int rowIndex = 0;
            if (ViewState["CurrentTable_h"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_h"];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        TextBox TB_Other = (TextBox)GV_Other.Rows[rowIndex].Cells[1].FindControl("TB_Other");
                        //RadioButtonList rb_Other = (RadioButtonList)GV_Other.Rows[rowIndex].Cells[1].FindControl("rb_Other");

                        TB_Other.Text = dt.Rows[i]["Column1"].ToString();
                        //rb_Other.SelectedValue = dt.Rows[i]["Column1"].ToString();

                        rowIndex++;
                    }
                }
            }
        }
        private void SetRowData_Other()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_h"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_h"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        TextBox TB_Other = (TextBox)GV_Other.Rows[rowIndex].Cells[1].FindControl("TB_Other");
                        //RadioButtonList rb_Other = (RadioButtonList)GV_Other.Rows[rowIndex].Cells[1].FindControl("rb_Other");

                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;

                        dtCurrentTable.Rows[i - 1]["Column1"] = TB_Other.Text;
                        // dtCurrentTable.Rows[i - 1]["Column1"] = rb_Other.SelectedValue;

                        rowIndex++;
                    }

                    ViewState["CurrentTable_h"] = dtCurrentTable;
                    //grvStudentDetails.DataSource = dtCurrentTable;
                    //grvStudentDetails.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }
            //SetPreviousData();
        }
        protected void Imbt_otherAdd_Click(object sender, ImageClickEventArgs e)
        {
            if (Session["User"]!= null)
            {
                AddNewRowToGrid_Other();
            }
            else
            {
                Response.Redirect("Login.aspx");
            }

        }
        protected void GV_Other_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            SetRowData_Other();
            if (ViewState["CurrentTable_h"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_h"];
                DataRow drCurrentRow = null;
                int rowIndex = Convert.ToInt32(e.RowIndex);
                if (dt.Rows.Count > 1)
                {
                    dt.Rows.Remove(dt.Rows[rowIndex]);
                    drCurrentRow = dt.NewRow();
                    ViewState["CurrentTable_h"] = dt;
                    GV_Other.DataSource = dt;
                    GV_Other.DataBind();

                    for (int i = 0; i < GV_Other.Rows.Count - 1; i++)
                    {
                        GV_Other.Rows[i].Cells[0].Text = Convert.ToString(i + 1);
                    }
                    SetPreviousData_Other();
                }
            }
        }
        //---------------------------------------------

        // Gridview งานทำนุบำรุงศิลปะวัฒนธรรม CurrentTable_i
        private void AddNewRowToGrid_Culture()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_i"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_i"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        //extract the TextBox values
                        TextBox TB_culture = (TextBox)GV_culture.Rows[rowIndex].Cells[1].FindControl("TB_culture");

                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;

                        dtCurrentTable.Rows[i - 1]["Column1"] = TB_culture.Text;

                        rowIndex++;
                    }
                    dtCurrentTable.Rows.Add(drCurrentRow);
                    ViewState["CurrentTable_i"] = dtCurrentTable;

                    GV_culture.DataSource = dtCurrentTable;
                    GV_culture.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }

            //Set Previous Data on Postbacks
            SetPreviousData_Culture();
        }
        private void SetPreviousData_Culture()
        {
            int rowIndex = 0;
            if (ViewState["CurrentTable_i"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_i"];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        TextBox TB_culture = (TextBox)GV_culture.Rows[rowIndex].Cells[1].FindControl("TB_culture");

                        TB_culture.Text = dt.Rows[i]["Column1"].ToString();

                        rowIndex++;
                    }
                }
            }
        }
        private void SetRowData_Culture()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_i"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_i"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        TextBox TB_culture = (TextBox)GV_culture.Rows[rowIndex].Cells[1].FindControl("TB_culture");

                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;

                        dtCurrentTable.Rows[i - 1]["Column1"] = TB_culture.Text;

                        rowIndex++;
                    }

                    ViewState["CurrentTable_i"] = dtCurrentTable;
                    //grvStudentDetails.DataSource = dtCurrentTable;
                    //grvStudentDetails.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }
            //SetPreviousData();
        }
        protected void Imbt_cultureAdd_Click(object sender, ImageClickEventArgs e)
        {
            if (Session["User"]!= null)
            {
                AddNewRowToGrid_Culture();
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
        }
        protected void GV_culture_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            SetRowData_Culture();
            if (ViewState["CurrentTable_i"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_i"];
                DataRow drCurrentRow = null;
                int rowIndex = Convert.ToInt32(e.RowIndex);
                if (dt.Rows.Count > 1)
                {
                    dt.Rows.Remove(dt.Rows[rowIndex]);
                    drCurrentRow = dt.NewRow();
                    ViewState["CurrentTable_i"] = dt;
                    GV_culture.DataSource = dt;
                    GV_culture.DataBind();

                    for (int i = 0; i < GV_culture.Rows.Count - 1; i++)
                    {
                        GV_culture.Rows[i].Cells[0].Text = Convert.ToString(i + 1);
                    }
                    SetPreviousData_Culture();
                }
            }
        }
        //--------------------------------------------

        //Gridview งานพัฒนานักศึกษา CurrentTable_j
        private void AddNewRowToGrid_Developer()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_j"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_j"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        //extract the TextBox values
                        TextBox TB_developer = (TextBox)GV_developer.Rows[rowIndex].Cells[1].FindControl("TB_developer");
                        RadioButtonList rb_developer = (RadioButtonList)GV_developer.Rows[rowIndex].Cells[1].FindControl("rb_developer");

                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;

                        dtCurrentTable.Rows[i - 1]["Column1"] = TB_developer.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = rb_developer.SelectedValue;

                        rowIndex++;
                    }
                    dtCurrentTable.Rows.Add(drCurrentRow);
                    ViewState["CurrentTable_j"] = dtCurrentTable;

                    GV_developer.DataSource = dtCurrentTable;
                    GV_developer.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }

            //Set Previous Data on Postbacks
            SetPreviousData_Developer();
        }
        private void SetPreviousData_Developer()
        {
            int rowIndex = 0;
            if (ViewState["CurrentTable_j"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_j"];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        TextBox TB_developer = (TextBox)GV_developer.Rows[rowIndex].Cells[1].FindControl("TB_developer");
                        RadioButtonList rb_developer = (RadioButtonList)GV_developer.Rows[rowIndex].Cells[1].FindControl("rb_developer");

                        TB_developer.Text = dt.Rows[i]["Column1"].ToString();
                        rb_developer.SelectedValue = dt.Rows[i]["Column1"].ToString();

                        rowIndex++;
                    }
                }
            }
        }
        private void SetRowData_Developer()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_j"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_j"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        TextBox TB_developer = (TextBox)GV_developer.Rows[rowIndex].Cells[1].FindControl("TB_developer");
                        RadioButtonList rb_developer = (RadioButtonList)GV_developer.Rows[rowIndex].Cells[1].FindControl("rb_developer");

                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;

                        dtCurrentTable.Rows[i - 1]["Column1"] = TB_developer.Text;
                        dtCurrentTable.Rows[i - 1]["Column1"] = rb_developer.SelectedValue;

                        rowIndex++;
                    }

                    ViewState["CurrentTable_j"] = dtCurrentTable;
                    //grvStudentDetails.DataSource = dtCurrentTable;
                    //grvStudentDetails.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }
            //SetPreviousData();
        }
        protected void Imbt_developerAdd_Click(object sender, ImageClickEventArgs e)
        {
            if (Session["User"]!= null)
            {
               AddNewRowToGrid_Developer(); 
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
        }
        protected void GV_developer_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            SetRowData_Developer();
            if (ViewState["CurrentTable_j"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_j"];
                DataRow drCurrentRow = null;
                int rowIndex = Convert.ToInt32(e.RowIndex);
                if (dt.Rows.Count > 1)
                {
                    dt.Rows.Remove(dt.Rows[rowIndex]);
                    drCurrentRow = dt.NewRow();
                    ViewState["CurrentTable_j"] = dt;
                    GV_developer.DataSource = dt;
                    GV_developer.DataBind();

                    for (int i = 0; i < GV_developer.Rows.Count - 1; i++)
                    {
                        GV_developer.Rows[i].Cells[0].Text = Convert.ToString(i + 1);
                    }
                    SetPreviousData_Developer();
                }
            }
        }
        //------------------------------------------

        //Gridview งานบริหาร/งานส่วนกลาง CurrentTable_k
        private void AddNewRowToGrid_Management()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_k"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_k"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        //extract the TextBox values
                        DropDownList dd_management = (DropDownList)GV_management.Rows[rowIndex].Cells[1].FindControl("dd_management");

                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;

                        dtCurrentTable.Rows[i - 1]["Column1"] = dd_management.SelectedValue;

                        rowIndex++;
                    }
                    dtCurrentTable.Rows.Add(drCurrentRow);
                    ViewState["CurrentTable_k"] = dtCurrentTable;

                    GV_management.DataSource = dtCurrentTable;
                    GV_management.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }

            //Set Previous Data on Postbacks
            SetPreviousData_Management();
        }
        private void SetPreviousData_Management()
        {
            int rowIndex = 0;
            if (ViewState["CurrentTable_k"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_k"];
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DropDownList dd_management = (DropDownList)GV_management.Rows[rowIndex].Cells[1].FindControl("dd_management");

                        dd_management.SelectedValue = dt.Rows[i]["Column1"].ToString();

                        rowIndex++;
                    }
                }
            }
        }
        private void SetRowData_Management()
        {
            int rowIndex = 0;

            if (ViewState["CurrentTable_k"] != null)
            {
                DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable_k"];
                DataRow drCurrentRow = null;
                if (dtCurrentTable.Rows.Count > 0)
                {
                    for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
                    {
                        DropDownList dd_management = (DropDownList)GV_management.Rows[rowIndex].Cells[1].FindControl("dd_management");

                        drCurrentRow = dtCurrentTable.NewRow();
                        drCurrentRow["RowNumber"] = i + 1;

                        dtCurrentTable.Rows[i - 1]["Column1"] = dd_management.SelectedValue;

                        rowIndex++;
                    }

                    ViewState["CurrentTable_k"] = dtCurrentTable;
                    //grvStudentDetails.DataSource = dtCurrentTable;
                    //grvStudentDetails.DataBind();
                }
            }
            else
            {
                Response.Write("ViewState is null");
            }
            //SetPreviousData();
        }
        protected void Imbt_managementAdd_Click(object sender, ImageClickEventArgs e)
        {
            if (Session["User"]!= null)
            {
               AddNewRowToGrid_Management(); 
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
        }
        protected void GV_management_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            SetRowData_Management();
            if (ViewState["CurrentTable_k"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable_k"];
                DataRow drCurrentRow = null;
                int rowIndex = Convert.ToInt32(e.RowIndex);
                if (dt.Rows.Count > 1)
                {
                    dt.Rows.Remove(dt.Rows[rowIndex]);
                    drCurrentRow = dt.NewRow();
                    ViewState["CurrentTable_k"] = dt;
                    GV_management.DataSource = dt;
                    GV_management.DataBind();

                    for (int i = 0; i < GV_management.Rows.Count - 1; i++)
                    {
                        GV_management.Rows[i].Cells[0].Text = Convert.ToString(i + 1);
                    }
                    SetPreviousData_Management();
                }
            }
        }

        protected void bt_savedata_Click(object sender, EventArgs e)
        {
            if (Session["User"]!= null)
            {
               DataTable table_Course = new DataTable();
            DataRow dr = null;
            int i = 0, j = 0, k = 0;
            table_Course.Columns.Add(new DataColumn("Name_Subject", typeof(string)));
            table_Course.Columns.Add(new DataColumn("Degree", typeof(string)));
            table_Course.Columns.Add(new DataColumn("Student_Group", typeof(string)));
            table_Course.Columns.Add(new DataColumn("Student_Number", typeof(string)));
            table_Course.Columns.Add(new DataColumn("Theory_Student", typeof(string)));
            table_Course.Columns.Add(new DataColumn("TB_practiceStudent", typeof(string)));
            table_Course.Columns.Add(new DataColumn("Course", typeof(string)));
            table_Course.Columns.Add(new DataColumn("Coach_Tea", typeof(string)));
            table_Course.Columns.Add(new DataColumn("theory_tea", typeof(string)));
            table_Course.Columns.Add(new DataColumn("practiceTeacher", typeof(string)));
            table_Course.Columns.Add(new DataColumn("TotalJob", typeof(string)));

            for (i = 0; i <= GV_CourseList.Rows.Count - 1; i++)
            {

                TextBox TB_CourseList = (TextBox)GV_CourseList.Rows[i].FindControl("TB_CourseList");
                CheckBoxList cb_list = (CheckBoxList)GV_CourseList.Rows[i].FindControl("CB_Degree");
                TextBox tb_stdgroup = (TextBox)GV_CourseList.Rows[i].FindControl("TB_studentGroup");
                TextBox tb_stdgnum = (TextBox)GV_CourseList.Rows[i].Cells[1].FindControl("TB_studentNumber");
                TextBox tb_theorystd = (TextBox)GV_CourseList.Rows[i].FindControl("TB_TheoryStudent");
                TextBox tb_practicestd = (TextBox)GV_CourseList.Rows[i].FindControl("TB_practiceStudent");
                DropDownList dd_regular = (DropDownList)GV_CourseList.Rows[i].FindControl("DD_Regular");
                RadioButtonList rb_Course = (RadioButtonList)GV_CourseList.Rows[i].FindControl("RB_Course");
                TextBox tb_theory_tea = (TextBox)GV_CourseList.Rows[i].FindControl("TB_TheoryTeacher");
                TextBox tb_practiceTeacher = (TextBox)GV_CourseList.Rows[i].FindControl("TB_practiceTeacher");

                  if (TB_CourseList.Text != "" && tb_stdgroup.Text != "" && tb_stdgnum.Text != "" && tb_theorystd.Text != "" && tb_practicestd.Text != "" && tb_theory_tea.Text != "" && tb_practiceTeacher.Text != "")
                    {
                        if (rb_Course.SelectedValue.ToString() == "0")
                        {

                            if (tb_practicestd.Text != "")
                            {
                                Practice = 1.75 * Convert.ToDouble(tb_practicestd.Text);
                                if (Practice > 3.5)
                                {
                                    Practice = 3.5;
                                }

                            }
                            else
                            {
                                Practice = 0;
                            }
                            if (Convert.ToInt32(tb_stdgnum.Text) > 100)
                            {
                                Stwork = (6.5 * Convert.ToDouble(tb_stdgroup.Text)) + Practice;
                                TotalWork = string.Format("{0:F2}", Stwork);
                            }
                            if (Convert.ToInt32(tb_stdgnum.Text) > 70)
                            {
                                Stwork = (5.5 * Convert.ToDouble(tb_stdgroup.Text)) + Practice;
                                TotalWork = string.Format("{0:F2}", Stwork);
                            }
                            if (Convert.ToInt32(tb_stdgnum.Text) > 40)
                            {
                                Stwork = (4.5 * Convert.ToDouble(tb_stdgroup.Text)) + Practice;
                                TotalWork = string.Format("{0:F2}", Stwork);
                            }
                            else
                            {
                                Stwork = (3.5 * Convert.ToDouble(tb_stdgroup.Text)) + Practice;
                                TotalWork = string.Format("{0:F2}", Stwork);
                            }
                        }
                        else
                        {

                            Stwork = Convert.ToDouble(tb_stdgroup.Text) + Practice;
                            TotalWork = string.Format("{0:F2}", Stwork);
                        }

                        dr = table_Course.NewRow();
                        dr["Name_Subject"] = TB_CourseList.Text;
                        dr["Degree"] = cb_list.SelectedItem.Text;
                        dr["Student_Group"] = tb_stdgroup.Text;
                        dr["Student_Number"] = tb_stdgnum.Text;
                        dr["Theory_Student"] = tb_theorystd.Text;
                        dr["TB_practiceStudent"] = tb_practicestd.Text;
                        dr["Course"] = dd_regular.SelectedItem.Text;
                        dr["Coach_Tea"] = rb_Course.SelectedItem.Text;
                        dr["theory_tea"] = tb_theory_tea.Text;
                        dr["practiceTeacher"] = tb_practiceTeacher.Text;
                        dr["TotalJob"] = TotalWork;

                        table_Course.Rows.Add(dr);
                    }
                    else
                    {
                        break;
                    }


                }

            //--------------------------------------------------------ที่ปรึกษาโครงงาน----------------------------------------------------
            Stwork = 0.00;
            TotalWork = "";
            DataTable table_Adviser = new DataTable();
            DataRow dr12 = null;
            i = 0;
            j = 0;
            k = 0;

            table_Adviser.Columns.Add(new DataColumn("Subject_Adviser", typeof(string)));
            table_Adviser.Columns.Add(new DataColumn("Adviser", typeof(string)));
            table_Adviser.Columns.Add(new DataColumn("GroupNum_Adviser", typeof(string)));
            table_Adviser.Columns.Add(new DataColumn("stdnum_Adviser", typeof(string)));
            table_Adviser.Columns.Add(new DataColumn("Degree_adviser", typeof(string)));
            table_Adviser.Columns.Add(new DataColumn("TotalJob", typeof(string)));

            for (i = 0; i <= GV_Adviser.Rows.Count - 1; i++)
            {

                TextBox TB_Subject_Adviser = (TextBox)GV_Adviser.Rows[i].FindControl("TB_Subject_Adviser");
                RadioButtonList rb_Adviser = (RadioButtonList)GV_Adviser.Rows[i].FindControl("rb_Adviser");
                TextBox TB_GroupNum_Adviser = (TextBox)GV_Adviser.Rows[i].FindControl("TB_GroupNum_Adviser");
                TextBox TB_stdnum_Adviser = (TextBox)GV_Adviser.Rows[i].Cells[1].FindControl("TB_stdnum_Adviser");
                CheckBoxList CB_Degree_adviser = (CheckBoxList)GV_Adviser.Rows[i].FindControl("CB_Degree_adviser");

                if (TB_stdnum_Adviser.Text != "" && TB_Subject_Adviser.Text != "" && TB_GroupNum_Adviser.Text != "")
                {
                    if (rb_Adviser.SelectedValue == "0")
                    {
                        if (CB_Degree_adviser.SelectedValue == "0")
                        {
                            Stwork = 3.00;
                            TotalWork = string.Format("{0:F2}", Stwork);
                        }
                        else
                        {
                            Stwork = 3.50;
                            TotalWork = string.Format("{0:F2}", Stwork);
                        }
                    }
                    else
                    {
                        Stwork = 1.75;
                        TotalWork = string.Format("{0:F2}", Stwork);
                    }
                    dr12 = table_Adviser.NewRow();
                    dr12["Subject_Adviser"] = TB_Subject_Adviser.Text;
                    dr12["Adviser"] = rb_Adviser.SelectedItem.Text;
                    dr12["GroupNum_Adviser"] = TB_GroupNum_Adviser.Text;
                    dr12["stdnum_Adviser"] = TB_stdnum_Adviser.Text;
                    dr12["Degree_adviser"] = CB_Degree_adviser.SelectedItem.Text;
                    dr12["TotalJob"] = TotalWork;

                    table_Adviser.Rows.Add(dr12);
                }
                else
                {
                    break;

                }
            }

            //---------------------------------------สหกิจศึกษา--------------------------------------
            Stwork = 0.00;
            TotalWork = "";
            DataTable Cooperative = new DataTable();
            DataRow dr13 = null;
            i = 0;
            j = 0;
            k = 0;

            Cooperative.Columns.Add(new DataColumn("CooperativeName", typeof(string)));
            Cooperative.Columns.Add(new DataColumn("TB_Cooperative_num", typeof(string)));
            Cooperative.Columns.Add(new DataColumn("TotalJob", typeof(string)));

            for (i = 0; i <= GV_Cooperative.Rows.Count - 1; i++)
            {

                TextBox TB_CooperativeName = (TextBox)GV_Cooperative.Rows[i].FindControl("TB_CooperativeName");
                TextBox TB_Cooperative_num = (TextBox)GV_Cooperative.Rows[i].FindControl("TB_Cooperative_num");

                if ((TB_CooperativeName.Text != "") && (TB_Cooperative_num.Text != ""))
                {
                    Stwork = 3.5 * Convert.ToDouble(TB_Cooperative_num.Text);
                    TotalWork = string.Format("{0:F2}", Stwork);

                    dr13 = Cooperative.NewRow();
                    dr13["CooperativeName"] = TB_CooperativeName.Text;
                    dr13["TB_Cooperative_num"] = TB_Cooperative_num.Text;
                    dr13["TotalJob"] = TotalWork;

                    Cooperative.Rows.Add(dr13);
                }
                else
                {
                    break;
                }


            }


            //----------------------Resert2.1------------------
            TotalWork = "";
            Stwork = 0.00;
            DataTable Table_Reserch = new DataTable();
            DataRow dr21 = null;
            i = 0;
            j = 0;
            k = 0;
            //ตารางที่ 2.1 โครงการวิจัย
            Table_Reserch.Columns.Add(new DataColumn("Projectname", typeof(string)));
            Table_Reserch.Columns.Add(new DataColumn("Projectpeople", typeof(string)));
            Table_Reserch.Columns.Add(new DataColumn("persenpj", typeof(string)));
            Table_Reserch.Columns.Add(new DataColumn("fundProject", typeof(string)));
            Table_Reserch.Columns.Add(new DataColumn("startpj", typeof(string)));
            Table_Reserch.Columns.Add(new DataColumn("endpj", typeof(string)));
            Table_Reserch.Columns.Add(new DataColumn("TotalJob", typeof(string)));


            for (i = 0; i <= GV_Project.Rows.Count - 1; i++)
            {

                TextBox TB_Projectname = (TextBox)GV_Project.Rows[i].FindControl("TB_Projectname");
                RadioButtonList RB_Projectpeople = (RadioButtonList)GV_Project.Rows[i].FindControl("RB_Projectpeople");
                RadioButtonList rb_persenpj = (RadioButtonList)GV_Project.Rows[i].FindControl("rb_persenpj");
                TextBox TB_fundProject = (TextBox)GV_Project.Rows[i].Cells[1].FindControl("TB_fundProject");
                TextBox TB_startpj = (TextBox)GV_Project.Rows[i].FindControl("TB_startpj");
                TextBox TB_endpj = (TextBox)GV_Project.Rows[i].FindControl("TB_endpj");

                if (TB_Projectname.Text != "" && TB_fundProject.Text != "" && TB_startpj.Text != "" && TB_endpj.Text != "")
                {
                    if (RB_Projectpeople.SelectedValue.ToString() == "0")
                    {
                        Stwork = 10.50;
                        TotalWork = string.Format("{0:F2}", Stwork);
                        dr21 = Table_Reserch.NewRow();
                        dr21["Projectname"] = TB_Projectname.Text;
                        dr21["Projectpeople"] = RB_Projectpeople.SelectedItem.Text;
                        dr21["persenpj"] = "-";
                        dr21["fundProject"] = TB_fundProject.Text;
                        dr21["startpj"] = TB_startpj.Text;
                        dr21["endpj"] = TB_endpj.Text;
                        dr21["TotalJob"] = TotalWork;

                        Table_Reserch.Rows.Add(dr21);
                    }
                    if (RB_Projectpeople.SelectedValue.ToString() == "1")
                    {
                        if (rb_persenpj.SelectedValue.ToString() == "0")
                        {
                            Stwork = 7;
                            TotalWork = string.Format("{0:F2}", Stwork);
                            dr21 = Table_Reserch.NewRow();
                            dr21["Projectname"] = TB_Projectname.Text;
                            dr21["Projectpeople"] = RB_Projectpeople.SelectedItem.Text;
                            dr21["persenpj"] = rb_persenpj.SelectedItem.Text;
                            dr21["fundProject"] = TB_fundProject.Text;
                            dr21["startpj"] = TB_startpj.Text;
                            dr21["endpj"] = TB_endpj.Text;
                            dr21["TotalJob"] = TotalWork;

                            Table_Reserch.Rows.Add(dr21);
                        }
                        else if (rb_persenpj.SelectedValue.ToString() == "1")
                        {
                            Stwork = 5.25;
                            TotalWork = string.Format("{0:F2}", Stwork);
                            dr21 = Table_Reserch.NewRow();
                            dr21["Projectname"] = TB_Projectname.Text;
                            dr21["Projectpeople"] = RB_Projectpeople.SelectedItem.Text;
                            dr21["persenpj"] = rb_persenpj.SelectedItem.Text;
                            dr21["fundProject"] = TB_fundProject.Text;
                            dr21["startpj"] = TB_startpj.Text;
                            dr21["endpj"] = TB_endpj.Text;
                            dr21["TotalJob"] = TotalWork;

                            Table_Reserch.Rows.Add(dr21);
                        }
                        else if (rb_persenpj.SelectedValue.ToString() == "2")
                        {
                            Stwork = 3.5;
                            TotalWork = string.Format("{0:F2}", Stwork);
                            dr21 = Table_Reserch.NewRow();
                            dr21["Projectname"] = TB_Projectname.Text;
                            dr21["Projectpeople"] = RB_Projectpeople.SelectedItem.Text;
                            dr21["persenpj"] = rb_persenpj.SelectedItem.Text;
                            dr21["fundProject"] = TB_fundProject.Text;
                            dr21["startpj"] = TB_startpj.Text;
                            dr21["endpj"] = TB_endpj.Text;
                            dr21["TotalJob"] = TotalWork;


                            Table_Reserch.Rows.Add(dr21);
                        }
                        else if (rb_persenpj.SelectedValue.ToString() == "3")
                        {
                            Stwork = 1.75;
                            TotalWork = string.Format("{0:F2}", Stwork);
                            dr21 = Table_Reserch.NewRow();
                            dr21["Projectname"] = TB_Projectname.Text;
                            dr21["Projectpeople"] = RB_Projectpeople.SelectedItem.Text;
                            dr21["persenpj"] = rb_persenpj.SelectedItem.Text;
                            dr21["fundProject"] = TB_fundProject.Text;
                            dr21["startpj"] = TB_startpj.Text;
                            dr21["endpj"] = TB_endpj.Text;
                            dr21["TotalJob"] = TotalWork;


                            Table_Reserch.Rows.Add(dr21);
                        }
                        else
                        {
                            break;
                        }
                    }

                }
                else
                {
                    break;
                }



                //dr = dt.NewRow();

                //Store the DataTable in ViewState
                // ViewState["CurrentTable_datasave"] = dt;


            }
            TotalWork = "";
            Stwork = 0.00;
            DataTable Table_Print = new DataTable();
            DataRow dr22 = null;
            i = 0;
            j = 0;
            k = 0;
            //ตารางที่ 2.2 การตีพิมพ์งานวิจัย
            Table_Print.Columns.Add(new DataColumn("Printname", typeof(string)));
            Table_Print.Columns.Add(new DataColumn("PrintAt", typeof(string)));
           // Table_Print.Columns.Add(new DataColumn("MagazinePrint", typeof(string)));
            Table_Print.Columns.Add(new DataColumn("PrintDate", typeof(string)));
            Table_Print.Columns.Add(new DataColumn("TotalJob", typeof(string)));


            for (i = 0; i <= GV_Print.Rows.Count - 1; i++)
            {

                TextBox TB_Printname = (TextBox)GV_Print.Rows[i].FindControl("TB_Printname");
                RadioButtonList rb_PrintAt = (RadioButtonList)GV_Print.Rows[i].FindControl("rb_PrintAt");
               // TextBox TB_MagazinePrint = (TextBox)GV_Print.Rows[i].FindControl("TB_MagazinePrint");
                TextBox TB_PrintDate = (TextBox)GV_Print.Rows[i].Cells[1].FindControl("TB_PrintDate");
                //if  For TotalWork2.2
                if (TB_Printname.Text != "" && TB_PrintDate.Text != "")
                {
                    if (rb_PrintAt.SelectedValue.ToString() == "0")
                    {
                        Stwork = 3.5;
                        TotalWork = string.Format("{0:F2}", Stwork);
                    }
                    if (rb_PrintAt.SelectedValue.ToString() == "1")
                    {
                        Stwork = 7;
                        TotalWork = string.Format("{0:F2}", Stwork);
                    }
                    dr22 = Table_Print.NewRow();
                    dr22["Printname"] = TB_Printname.Text;
                    dr22["PrintAt"] = rb_PrintAt.SelectedItem.Text;
                   // dr22["MagazinePrint"] = TB_MagazinePrint.Text;
                    dr22["PrintDate"] = TB_PrintDate.Text;
                    dr22["TotalJob"] = TotalWork;

                    Table_Print.Rows.Add(dr22);
                }
                else
                {
                    break;
                }

            }

            //***********คณะกรรมการ 3.1**********
            TotalWork = "";
            Stwork = 0.00;
            DataTable Table_Board = new DataTable();
            DataRow dr31 = null;
            i = 0;
            j = 0;
            k = 0;
            Table_Board.Columns.Add(new DataColumn("Boardname", typeof(string)));
            Table_Board.Columns.Add(new DataColumn("Boardeorder", typeof(string)));
            Table_Board.Columns.Add(new DataColumn("TotalJob", typeof(string)));

            for (i = 0; i <= GV_Board.Rows.Count - 1; i++)
            {

                TextBox TB_Boardname = (TextBox)GV_Board.Rows[i].FindControl("TB_Boardname");
                TextBox TB_Boardeorder = (TextBox)GV_Board.Rows[i].FindControl("TB_Boardeorder");

                //if  For TotalWork3.1
                if (TB_Boardname.Text != "" && TB_Boardeorder.Text != "")
                {
                    Stwork = 0.30;
                    TotalWork = string.Format("{0:F2}", Stwork);
                    dr31 = Table_Board.NewRow();
                    dr31["Boardname"] = TB_Boardname.Text;
                    dr31["Boardeorder"] = TB_Boardeorder.Text;
                    dr31["TotalJob"] = TotalWork;


                    Table_Board.Rows.Add(dr31);
                }
                else
                {
                    break;
                }


            }

            // ------------วิทยากร--------------
            TotalWork = "";
            Stwork = 0.00;
            DataTable Table_lecture = new DataTable();
            DataRow dr32 = null;
            i = 0;
            j = 0;
            k = 0;
            //ตารางที่ 3.2 การตีพิมพ์งานวิจัย
            Table_lecture.Columns.Add(new DataColumn("lecturename", typeof(string)));
            Table_lecture.Columns.Add(new DataColumn("Lecture", typeof(string)));
            Table_lecture.Columns.Add(new DataColumn("Hour", typeof(string)));
            Table_lecture.Columns.Add(new DataColumn("lecturedate", typeof(string)));
            Table_lecture.Columns.Add(new DataColumn("lecturelocation", typeof(string)));
            Table_lecture.Columns.Add(new DataColumn("lecturecredit", typeof(string)));
            Table_lecture.Columns.Add(new DataColumn("TotalJob", typeof(string)));


            for (i = 0; i <= GV_lecture.Rows.Count - 1; i++)
            {

                TextBox TB_lecturename = (TextBox)GV_lecture.Rows[i].FindControl("TB_lecturename");
                RadioButtonList rb_Lecture = (RadioButtonList)GV_lecture.Rows[i].FindControl("rb_Lecture");
                TextBox TB_Hour = (TextBox)GV_lecture.Rows[i].FindControl("TB_Hour");
                TextBox TB_lecturedate = (TextBox)GV_lecture.Rows[i].FindControl("TB_lecturedate");
                TextBox TB_lecturelocation = (TextBox)GV_lecture.Rows[i].Cells[1].FindControl("TB_lecturelocation");
                TextBox TB_lecturecredit = (TextBox)GV_lecture.Rows[i].Cells[1].FindControl("TB_lecturecredit");
                //if  For TotalWork3.2
                if (TB_lecturename.Text != "" && TB_Hour.Text != "" && TB_lecturedate.Text != "" && TB_lecturelocation.Text != "" && TB_lecturecredit.Text != "")
                {
                    if (rb_Lecture.SelectedValue.ToString() == "0")
                    {
                        Stwork = 1 * Convert.ToDouble(TB_Hour.Text);
                        TotalWork = string.Format("{0:F2}", Stwork);
                    }
                    if (rb_Lecture.SelectedValue.ToString() == "1")
                    {
                        Stwork = 0.5 * Convert.ToDouble(TB_Hour.Text);
                        TotalWork = string.Format("{0:F2}", Stwork);
                    }
                    if (Stwork > 7)
                    {
                        Stwork = 7;
                        TotalWork = string.Format("{0:F2}", Stwork);
                    }
                    dr32 = Table_lecture.NewRow();
                    dr32["lecturename"] = TB_lecturename.Text;
                    dr32["Lecture"] = rb_Lecture.SelectedItem.Text;
                    dr32["Hour"] = TB_Hour.Text;
                    dr32["lecturedate"] = TB_lecturedate.Text;
                    dr32["lecturelocation"] = TB_lecturelocation.Text;
                    dr32["lecturecredit"] = TB_lecturecredit.Text;
                    dr32["TotalJob"] = TotalWork;


                    Table_lecture.Rows.Add(dr32);
                }
                else
                {
                    break;
                }


            }

            //  -------------3.3 ผู้ทรงคุณวุฒิ ----------
            TotalWork = "";
            Stwork = 0.00;
            DataTable Table_Proficient = new DataTable();
            DataRow dr33 = null;
            i = 0;
            j = 0;
            k = 0;
            Table_Proficient.Columns.Add(new DataColumn("Proficient", typeof(string)));
            Table_Proficient.Columns.Add(new DataColumn("rbProficient", typeof(string)));
            Table_Proficient.Columns.Add(new DataColumn("TotalJob", typeof(string)));


            for (i = 0; i <= GV_Proficient.Rows.Count - 1; i++)
            {

                TextBox TB_Proficient = (TextBox)GV_Proficient.Rows[i].FindControl("TB_Proficient");
                RadioButtonList rb_Proficient = (RadioButtonList)GV_Proficient.Rows[i].FindControl("rb_Proficient");

                //if  For TotalWork3.3

                if (TB_Proficient.Text != "")
                {
                    Stwork = 2.00;
                    TotalWork = string.Format("{0:F2}", Stwork);

                    dr33 = Table_Proficient.NewRow();
                    dr33["Proficient"] = TB_Proficient.Text;
                    dr33["rbProficient"] = rb_Proficient.SelectedItem.Text;
                    dr33["TotalJob"] = TotalWork;

                    Table_Proficient.Rows.Add(dr33);
                }
                else
                {
                    break;
                }

            }
            //**************   3.4 อื่นๆๆๆๆๆๆๆๆๆๆๆๆ
            TotalWork = "";
            Stwork = 0.00;
            DataTable Table_Other = new DataTable();
            DataRow dr34 = null;
            i = 0;
            j = 0;
            k = 0;
            Table_Other.Columns.Add(new DataColumn("Other", typeof(string)));
            Table_Other.Columns.Add(new DataColumn("TotalJob", typeof(string)));


            for (i = 0; i <= GV_Other.Rows.Count - 1; i++)
            {

                TextBox TB_Other = (TextBox)GV_Other.Rows[i].FindControl("TB_Other");


                //if  For TotalWork3.4
                if (TB_Other.Text != "")
                {
                    if (Stwork < 7)
                    {
                        Stwork = 2;
                        TotalWork = string.Format("{0:F2}", Stwork);
                    }
                    if (Stwork >= 7)
                    {
                        Stwork = 7;
                        TotalWork = string.Format("{0:F2}", Stwork);
                    }
                    dr34 = Table_Other.NewRow();
                    dr34["Other"] = TB_Other.Text;
                    dr34["TotalJob"] = TotalWork;


                    Table_Other.Rows.Add(dr34);
                }
                else
                {
                    break;
                }


            }
            //---------------------งานทำนุบำรุงศิลปะวัฒนธรรม-------------------------------
            Stwork = 0.00;
            TotalWork = "";
            DataTable Table_culture = new DataTable();
            DataRow dr4 = null;
            i = 0;
            j = 0;
            k = 0;

            Table_culture.Columns.Add(new DataColumn("culture", typeof(string)));
            Table_culture.Columns.Add(new DataColumn("TotalJob", typeof(string)));

            for (i = 0; i <= GV_culture.Rows.Count - 1; i++)
            {

                TextBox TB_culture = (TextBox)GV_culture.Rows[i].FindControl("TB_culture");

                if (TB_culture.Text != "")
                {
                    if (TB_culture.Text != "")
                    {
                        Stwork = 1.50;
                        TotalWork = string.Format("{0:F2}", Stwork);
                    }
                    dr4 = Table_culture.NewRow();
                    dr4["culture"] = TB_culture.Text;
                    dr4["TotalJob"] = TotalWork;

                    Table_culture.Rows.Add(dr4);
                }
                else
                {
                    break;
                }


            }


            //----------------------------------งานพัฒนานักศึกษา-----------------------------------------
            Stwork = 0.00;
            TotalWork = "";
            DataTable Table_developer = new DataTable();
            DataRow dr5 = null;
            i = 0;
            j = 0;
            k = 0;

            Table_developer.Columns.Add(new DataColumn("developer", typeof(string)));
            Table_developer.Columns.Add(new DataColumn("rb_developer", typeof(string)));
            Table_developer.Columns.Add(new DataColumn("TotalJob", typeof(string)));

            for (i = 0; i <= GV_developer.Rows.Count - 1; i++)
            {

                TextBox TB_developer = (TextBox)GV_developer.Rows[i].FindControl("TB_developer");
                RadioButtonList rb_developer = (RadioButtonList)GV_developer.Rows[i].FindControl("rb_developer");
                if (TB_developer.Text != "")
                {
                    if (rb_developer.SelectedValue == "0")
                    {
                        Stwork = 1.50;
                        TotalWork = string.Format("{0:F2}", Stwork);
                    }
                    else
                    {
                        Stwork = 2.00;
                        TotalWork = string.Format("{0:F2}", Stwork);
                    }

                }
                else
                {
                    break;
                }


                dr5 = Table_developer.NewRow();
                dr5["developer"] = TB_developer.Text;
                dr5["rb_developer"] = rb_developer.SelectedItem.Text;
                dr5["TotalJob"] = TotalWork;

                Table_developer.Rows.Add(dr5);


            }


            //---------------------------------------งานบริหาร/งานส่วนกลาง---------------------------------------
            Stwork = 0.00;
            TotalWork = "";
            DataTable Table_management = new DataTable();
            DataRow dr6 = null;
            i = 0;
            j = 0;
            k = 0;

            Table_management.Columns.Add(new DataColumn("management", typeof(string)));
            Table_management.Columns.Add(new DataColumn("TotalJob", typeof(string)));

            for (i = 0; i <= GV_management.Rows.Count - 1; i++)
            {

                DropDownList dd_management = (DropDownList)GV_management.Rows[i].FindControl("dd_management");

                switch (dd_management.SelectedValue)
                {
                    case "0": Stwork = 35.00;
                        TotalWork = string.Format("{0:F2}", Stwork);
                        break;
                    case "1": Stwork = 30.00;
                        TotalWork = string.Format("{0:F2}", Stwork);
                        break;
                    case "2": Stwork = 30.00;
                        TotalWork = string.Format("{0:F2}", Stwork);
                        break;
                    case "3": Stwork = 26.00;
                        TotalWork = string.Format("{0:F2}", Stwork);
                        break;
                    case "4": Stwork = 24.00;
                        TotalWork = string.Format("{0:F2}", Stwork);
                        break;
                    case "5": Stwork = 20.00;
                        TotalWork = string.Format("{0:F2}", Stwork);
                        break;
                    case "6": Stwork = 16.00;
                        TotalWork = string.Format("{0:F2}", Stwork);
                        break;
                    case "7": Stwork = 14.00;
                        TotalWork = string.Format("{0:F2}", Stwork);
                        break;
                    case "8": Stwork = 14.00;
                        TotalWork = string.Format("{0:F2}", Stwork);
                        break;
                    case "9": Stwork = 12.00;
                        TotalWork = string.Format("{0:F2}", Stwork);
                        break;
                    case "10": Stwork = 20.00;
                        TotalWork = string.Format("{0:F2}", Stwork);
                        break;
                    case "11": Stwork = 16.00;
                        TotalWork = string.Format("{0:F2}", Stwork);
                        break;
                    case "12": Stwork = 16.00;
                        TotalWork = string.Format("{0:F2}", Stwork);
                        break;
                    case "13": Stwork = 16.00;
                        TotalWork = string.Format("{0:F2}", Stwork);
                        break;
                    case "14": Stwork = 12.00;
                        TotalWork = string.Format("{0:F2}", Stwork);
                        break;
                    case "15": Stwork = 10.00;
                        TotalWork = string.Format("{0:F2}", Stwork);
                        break;
                    case "16": Stwork = 0.00;
                        TotalWork = string.Format("{0:F2}", Stwork);
                        break;
                }

                dr6 = Table_management.NewRow();
                dr6["management"] = dd_management.SelectedItem.Text;
                dr6["TotalJob"] = TotalWork;

                Table_management.Rows.Add(dr6);


            }

            //-----------------------------------------------------------------------
           
           

            if (Table_Reserch.Rows.Count > 0 && table_Course.Rows.Count > 0 && table_Adviser.Rows.Count>0 && Cooperative.Rows.Count>0 && Table_Print.Rows.Count>0
                && Table_lecture.Rows.Count>0 && Table_Board.Rows.Count>0 && Table_Proficient.Rows.Count>0 && Table_Other.Rows.Count>0 && Table_developer.Rows.Count>0
                && Table_culture.Rows.Count>0 && txtYears.Text !="")
            {

                Session["Year"] = txtYears.Text;
                Session["Term"] = rblTerm.SelectedValue;
                Session["Data_Reserch"] = Table_Reserch;
                Session["Data_Course"] = table_Course;
                Session["Data_Adviser"] = table_Adviser;
                Session["Data_Cooperative"] = Cooperative;
                Session["Data_Print"] = Table_Print;
                Session["Data_lecture"] = Table_lecture;
                Session["Data_Board"] = Table_Board;
                Session["Data_Proficient"] = Table_Proficient;
                Session["Data_Other"] = Table_Other;
                Session["Table_management"] = Table_management;
                Session["Table_developer"] = Table_developer;
                Session["Table_culture"] = Table_culture;
                Response.Redirect("data.aspx");
            }
            else
            {
                Response.Write(@"<script language='javascript'>alert('คุณกรอกข้อมูลไม่ครบถ้วน กรุณาตรวจสอบอีกครั้ง')</script>");
            } 
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
            

        }

        protected void bt_cancle_Click(object sender, EventArgs e)
        {
            if (Session["User"]!=null)
            {
                Response.Redirect("Default.aspx");
            }
            else
            {
                Response.Redirect("Login.aspx");
            }
        }
        //-----------------------------------------


    }
}